<!DOCTYPE html>
<html>
    
    <head>
        <meta charset="utf-8">
        <title>
            X-admin v1.0
        </title>
        <meta name="renderer" content="webkit">
        <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
        <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
        <meta name="apple-mobile-web-app-status-bar-style" content="black">
        <meta name="apple-mobile-web-app-capable" content="yes">
        <meta name="format-detection" content="telephone=no">
        <link rel="stylesheet" href="./css/x-admin.css" media="all">
    </head>
    
    <body>
        <div class="x-body">
            <form class="layui-form">
                <div class="layui-form-item">
                    <label for="sidu" class="layui-form-label">
                        <span class="x-red">*</span>丝度
                    </label>
                    <div class="layui-input-inline">
                        <input type="text" id="sidu" name="sidu" required lay-verify="required"
                        autocomplete="off" class="layui-input">
                    </div>
                    <!--<div class="layui-form-mid layui-word-aux">
                        <span class="x-red">*</span>将会成为您唯一的登入名
                    </div>-->
                </div>
                <div class="layui-form-item">
                    <label for="style" class="layui-form-label">
                        <span class="x-red">*</span>规格
                    </label>
                    <div class="layui-input-inline">
                        <input type="text" id="style" name="style" required="" lay-verify="style"
                        autocomplete="off" class="layui-input">
                    </div>
                   <!-- <div class="layui-form-mid layui-word-aux">
                        <span class="x-red">*</span>将会成为您唯一的登入名
                    </div>-->
                </div>
                <div class="layui-form-item">
                    <label for="desc" class="layui-form-label">
                        <span class="x-red">*</span>备注
                    </label>
                    <div class="layui-input-inline">
                        <input type="text" id="desc" name="desc" required="" lay-verify="desc"
                        autocomplete="off" class="layui-input">
                    </div>
                    <!--<div class="layui-form-mid layui-word-aux">
                        <span class="x-red">*</span>
                    </div>-->
                </div>
                <div class="layui-form-item">
                    <label for="role" class="layui-form-label">
                        <span class="x-red">*</span>上级
                    </label>
                    <div class="layui-input-inline">
                      <select name="role" id="role" >
                        <option value="0">顶层</option>
                        <!--<option value="超级管理员">超级管理员</option>
                        <option value="编辑人员">编辑人员</option>
                        <option value="问题维护">问题维护</option>-->
                      </select>
                    </div>
                </div>

                <div class="layui-form-item">
                    <!--<label for="L_repass" class="layui-form-label">
                    </label>-->
                    <button  class="layui-btn" lay-filter="add" lay-submit="">
                        增加
                    </button>
                </div>
            </form>
        </div>
        <script src="./lib/layui/layui.js" charset="utf-8">
        </script>
        <script src="./js/x-layui.js" charset="utf-8">
        </script>
        <script>
            layui.use(['form','layer'], function(){
                $ = layui.jquery;
              var form = layui.form()
              ,layer = layui.layer;
            
              //自定义验证规则
              form.verify({
                sidu: function(value){
                  if(value.length < 1){
                    return '丝度至少得1个字符';
                  }
                }
              });

              //监听提交
              form.on('submit(add)', function(data){
                  alert(JSON.stringify(data));
                  alert(JSON.stringify(data.field));
                //发异步，把数据提交给php
                  $.post("t-add.do",data.field,function (res) {
                      if(res.code==0){
                          layer.alert("增加成功", {icon: 6},function () {
                              // 获得frame索引
                              var index = parent.layer.getFrameIndex(window.name);
                              //关闭当前frame
                              parent.layer.close(index);
                              parent.location.reload();//刷新父窗口
                          });
                      }else{
                          layer.alert("发生错误："+res.msg);
                      }
                  });

                return false;
              });
              
              
            });
        </script>

    </body>

</html>